package com.lxw.consumer;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lxw.service.ICmsPageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class PostPageConsumerMq {
    @Autowired
    ICmsPageService cmsPageService;

    @RabbitListener(queues = "${fhs.mq.queue}")
    @RabbitHandler
    public void process(String msg){
        log.info("页面消费{}",msg);
        JSONObject jsonObject = JSON.parseObject(msg);
        String pageId = jsonObject.getString("pageId");
        // 把前面业务保存的静态化HTML文件写入磁盘  1读取文件  2.磁盘物理路径 3.写入
        try {
            cmsPageService.writeFile(pageId);
        } catch (Exception e) {
            e.printStackTrace();
            //
            log.error("页面发布失败,接收数据为:{}",msg);
        }

    }
}
